package com.tanger.im.service.notice;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import com.tanger.im.entity.ImUserGroupNotice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Description 用户控制层
 * @Author Hchenbin
 * @Date 2022/8/1 9:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/tanger/api/im/user:group-notice/{groupId}")
@Api(value = "IM:IM用户群/组:通知",tags="IM:IM用户群/组:通知")
public class IMUserGroupNoticeController extends AbstractController{

    @Autowired
    private IMUserGroupNoticeService service;

    @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long")
    @ApiOperation(value = "组群通知列表查询")
    @GetMapping("/findAll")
    public ActionResult<List<ImUserGroupNotice>> findAll(@PathVariable Long groupId){
        if (StringUtil.isNull(groupId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findAll(groupId));
    }

    @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long")
    @ApiOperation(value = "最新组群通知查询")
    @GetMapping("/findOne")
    public ActionResult<ImUserGroupNotice> findOne(@PathVariable Long groupId){
        if (StringUtil.isNull(groupId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOne(groupId));
    }

    @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long")
    @ApiOperation(value = "组群通知发布")
    @PostMapping("/save")
    public ActionResult save(@PathVariable Long groupId,@RequestBody ImUserGroupNotice notice) {
        if (StringUtil.isNull(groupId)
                || Objects.isNull(notice) || StringUtil.isNull(notice.getNotice())) {
            return ActionResult.buildResultError("参数缺失");
        }

        return service.save(groupId, notice);
    }
}

